	<template>
	<el-row class="header">
		<el-col :span="10">
			<el-row :gutter="20" v-if="searchByIdName">
				<el-col :span="7">
					<span>学号：</span>
					<el-input v-model.number="searchByIdName.stuId" />
				</el-col>
				<el-col :span="7">
					<span>姓名：</span>
					<el-input v-model.trim="searchByIdName.stuName" />
				</el-col>
				<el-col :span="3">
					<el-button class="btn" @click="submitSearchByIdName"
						><el-icon><Search /></el-icon>查询</el-button
					>
				</el-col>
				<el-col :span="3">
					<slot name="reset"></slot>
				</el-col>
			</el-row>

			<!-- 留言搜索 -->
			<el-row :gutter="20" v-if="searchMsgCard">
				<el-col :span="8">
					<span>学号：</span>
					<el-input v-model.number="searchMsgCard.stuId" />
				</el-col>
				<el-col :span="3">
					<el-button class="btn" @click="submitSearchMsgCard">
						<el-icon><Search /></el-icon>
						查询</el-button
					>
				</el-col>
				<el-col :span="3">
					<el-button class="btn" @click="resetSearchMsgCard">重置</el-button>
				</el-col>
			</el-row>
		</el-col>
	</el-row>
</template>

<script setup>
import { getStuIdName } from '@/utils/axios/master'
import { useUserStore } from '@/stores/userStore'
import { queryOneStuMessage, queryAllMessage } from '@/utils/axios/domiRequests'
import useRegStore from '@/stores/useReg'
import { Search } from '@element-plus/icons'

const { userInfo } = useUserStore()
const { handleCheckId } = useRegStore()
const $emit = defineEmits(['get-res'])
// import

// 留言搜索
const searchMsgCard = defineModel('searchMsgCard')

// 通过学号和姓名进行查询
const searchByIdName = defineModel('searchByIdName')
// 留校人员

/* 
1.searchByIdName.flag
 1:// 返回学生所有信息

*/
async function submitSearchByIdName() {
	const { flag, stuId, stuName } = searchByIdName.value

	if (flag === 2) {
		if (stuId || stuName) {
			if (stuId) {
				if (!handleCheckId(stuId)) return
			}
			let { data } = await getStuIdName({
				stuId: stuId,
				stuName: stuName,
				buildId: userInfo.buildId,
			})
			searchByIdName.value.stu = data
		} else {
			delete searchByIdName.value.stu
		}
	}
	if (flag === 1) {
		if (stuId || stuName) {
			console.log(Number.parseInt(stuId))
			if (stuId) {
				if (!handleCheckId(stuId)) return
			}
			if (Number.isNaN(Number.parseInt(stuId))) {
				let { data } = await getStuIdName({ stuId: 0, stuName: stuName })
				searchByIdName.value.stu = data
				return
			}
			let { data } = await getStuIdName({ stuId: stuId, stuName: stuName })
			searchByIdName.value.stu = data
		} else {
			delete searchByIdName.value.stu
		}
	}
}

// 留言搜索
async function submitSearchMsgCard() {
	if (!handleCheckId(searchMsgCard.value.stuId)) return
	let { data } = await queryOneStuMessage({ stuId: parseInt(searchMsgCard.value.stuId), currentPage: 1 })
	$emit('get-res', data)
}

// 重置留言搜索
async function resetSearchMsgCard() {
	let { data } = await queryAllMessage({ currentPage: 1, pageSize: 10 })
	searchMsgCard.value.stuId = ''
	$emit('get-res', data)
}
</script>

<style scoped lang="sass">
.el-select
  width: 100px


.header
  margin-bottom: 20px

.el-input
    width: 100px
.btn
    background: rgb(0,202,237)
    color: #ffff
</style>
